import {createContext, useContext} from 'react';
import useImmerState, {setState} from './hooks/useImmerState';

export interface GlobalState {
  projectId: string,
  iconListLoaded: boolean,
}

const initialState: GlobalState = {
  projectId: '0',
  iconListLoaded: false
};

const useGlobalState = () => {
  const {state, setState} = useContext(GlobalContext);
  return {
    globalState: state,
    setGlobalState: setState
  };
};

export const useCreateGlobalState = () => {
  const [state, setState] = useImmerState(initialState);
  return {
    state,
    setState
  };
};

export interface IGlobalContext {
  state: GlobalState,
  setState: setState<GlobalState>
}

export default useGlobalState;
export const GlobalContext = createContext({} as IGlobalContext);